package com.grieous.wow.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.grieous.wow.dao.ContentDao;
import com.grieous.wow.entity.Content;
import com.grieous.wow.entity.Domain;
import com.grieous.wow.entity.Tag;

@Repository("contentDao")
public class ContentDaoImpl extends SqlSessionDaoSupport implements ContentDao {

	@Override
	public int add(Content t) {
		return getSqlSession().insert("mybatis.mapper.ContentMapper.insertSelective",
				t);

	}

	@Override
	public int delete(Content t) {
		return 0;
	}

	@Override
	public int delete(Map<String, Object> map) {
		return getSqlSession().delete("mybatis.mapper.ContentMapper.deleteByMap", map);

	}

	@Override
	public int update(Content t) {
		return getSqlSession().update("mybatis.mapper.ContentMapper.updateById", t);

	}

	@Override
	public int  update(Map<String, Object> map) {
		return getSqlSession().update("mybatis.mapper.ContentMapper.updateByMap", map);

	}

	@Override
	public List<Content> findListByCondition(Map<String, Object> map) {
		List<Content> list = getSqlSession().selectList(
				"mybatis.mapper.ContentMapper.getContent", map);
		return list;
	}

	@Override
	public int findCountByCondition(Map<String, Object> map) {
		Object obj = getSqlSession().selectOne(
				"mybatis.mapper.ContentMapper.getContentCount", map);
		return (Integer) (obj == null ? 0 : obj);
	}

	@Override
	public List<Content> getContentByTag(Map<String, Object> map) {
		List<Content> list = getSqlSession().selectList(
				"mybatis.mapper.ContentMapper.getContentByTag", map);
		return list;
	}

	

	@Override
	public List<Tag> getTagWidthContent(Map<String, Object> map) {
		List<Tag> list = getSqlSession().selectList(
				"mybatis.mapper.TagMapper.getTagWidthContent", map);
		return list;
	}

	public int insertDomain(Domain domain) {
		return getSqlSession().insert("mybatis.mapper.ContentMapper.insertDomain",
				domain);

	}

	@Override
	public int updateDomain(Domain domain) {
		return getSqlSession().update("mybatis.mapper.ContentMapper.updateDomain",
				domain);
	}

	@Override
	public int deleteDomain(Map<String, Object> map) {
		return getSqlSession()
				.delete("mybatis.mapper.ContentMapper.deleteDomain", map);

	}

	@Override
	public List<Domain> getDomain(Map<String, Object> map) {
		return getSqlSession().selectList(
				"mybatis.mapper.ContentMapper.getDomain", map);
	}

	@Override
	public int getDomainCount(Map<String, Object> map) {
		Object obj = getSqlSession().selectOne(
				"mybatis.mapper.ContentMapper.getDomainCount", map);
		return (Integer) (obj == null ? 0 : obj);
	}

	
	@Override
	public int insertTag(Tag tag) {
		return getSqlSession().insert("mybatis.mapper.TagMapper.insertTag", tag);

	}

	@Override
	public int updateTag(Tag tag) {
		return getSqlSession().update("mybatis.mapper.TagMapper.updateTag", tag);

	}

	public List<Tag> getTag(Map<String, Object> map) {
		List<Tag> list = getSqlSession().selectList(
				"mybatis.mapper.TagMapper.getTag", map);
		return list;
	}
	@Override
	public int  deleteTag(Map<String, Object> map) {
		return getSqlSession().delete("mybatis.mapper.TagMapper.deleteTag", map);

	}

	@Override
	public int getTagCount(Map<String, Object> map) {
		Object obj = getSqlSession().selectOne(
				"mybatis.mapper.TagMapper.getTagCount", map);
		return (Integer) (obj == null ? 0 : obj);
	}

}
